package com.linsir.lin.controller.omp;

import com.linsir.lin.dto.OrganizationDTO;
import com.linsir.lin.pojo.Organization;
import com.linsir.lin.pojo.Position;
import com.linsir.lin.pojo.PositionOrgan;
import com.linsir.lin.service.OrganizationService;
import com.linsir.lin.service.PositionOrganService;
import com.linsir.lin.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * @author ：linsir
 * @date ：Created in 2021/7/1 10:26
 * @description：组织结构人员职务
 * @modified By：
 * @version: 1.0.0
 */

@Controller
@RequestMapping(value = "/admin/")
public class OMPController {
    @Autowired
    private PositionService positionService;
    @Autowired
    private OrganizationService organizationService;
    @Autowired
    private PositionOrganService positionOrganService;
    /**
     * 组织结构列表
     * @return
     */
    @RequestMapping(value = "/organization", method = {RequestMethod.GET})
    public String organization() {
        return "organization/organization";
    }

    /**
     * @return
     */
    @RequestMapping(value = "/member", method = {RequestMethod.GET})
    public String member() {
        return "organization/member";
    }

    @RequestMapping(value = "/member/add", method = {RequestMethod.GET})
    public String addmember() {
        return "organization/member_add";
    }

    @RequestMapping(value = "/job", method = {RequestMethod.GET})
    public String job() {
        return "organization/job";
    }

    @RequestMapping(value = "/position", method = {RequestMethod.GET})
    public String position() {
        return "organization/position";
    }

    @RequestMapping(value = "/position/add", method = {RequestMethod.GET})
    public String addPosition() {
        return "organization/position_add";
    }

    @RequestMapping(value = "/position/edit/{positionId}",method = {RequestMethod.GET})
    public String editPosition(@PathVariable(value = "positionId") Integer positionId, ModelMap modelMap) throws InvocationTargetException, IllegalAccessException {
        Position position=positionService.getById(positionId);
        PositionOrgan positionOrgan=positionOrganService.getByPositionId(positionId);
        Organization organization=organizationService.getById(positionOrgan.getOrganId());
        modelMap.addAttribute("position",position);
        modelMap.addAttribute("positionOrgan",positionOrgan);
        modelMap.addAttribute("organization",organization);
        return "organization/position_edit";
    }
}
